<?php
/**
 * Created by PhpStorm.
 * User: yafex
 * Date: 2019/11/6
 * Time: 22:52
 */
class core_account extends L {

    /**
     * 描述 ：保存和修改账号信息
     * 参数 ：{
     *      account ：账号
     *      appKey ：应用Id
     *      appSecret ：应用密钥
     *      accessToken ：访问令牌
     *      refreshToken ：刷新令牌
     *      invalidDate ：失效时间
     *      state ：状态
     *      type ：类型 ali，pdd
     *      data ：接口返回的所有数据json
     * }
     * 作者 ：Zoro.Zhu
    **/
    public static function setAccount($params){
        if (!isset($params['account'])) {
            $result = array('state' => 401, 'info' => '账号不能为空');
        } else if (core_base::trans()) {
            $params['state'] = isset($params['state']) ? $params['state'] : 0;
            $data = addslashes(json_encode($params['data']));
            $sql = "INSERT INTO `vs_account`(
                `account`, `appKey`, `appSecret`, 
                `accessToken`, `refreshToken`, `invalidDate`, 
                `state`, `type`, `addDate`, 
                `data`
            ) VALUES (
                '{$params['account']}', '{$params['appKey']}', '{$params['appSecret']}', 
                '{$params['accessToken']}', '{$params['refreshToken']}', '{$params['invalidDate']}', 
                '{$params['state']}', '{$params['type']}', '" . date('Y-m-d H:i:s') . "',
                '{$data}') 
            ON DUPLICATE KEY UPDATE
                `appKey`=VALUES(`appKey`),
                `appSecret`=VALUES(`appSecret`),
                `accessToken`=VALUES(`accessToken`),
                `refreshToken`=VALUES(`refreshToken`),
                `invalidDate`=VALUES(`invalidDate`),
                `state`=VALUES(`state`),
                `type`=VALUES(`type`),
                `addDate`=VALUES(`addDate`),
                `data`=VALUES(`data`)";
            L::sql($sql);
        } else {
            $result = array('state' => 402, 'info' => '未开启事务');
        }
        empty($result) && $result = array('state' => 200, 'info' => '操作成功');
        core_base::trans($result);
        return $result;
    }

}